﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;

namespace SimplexEngine
{
    public class MeshBuffer : IMeshBuffer
    {
        // bounding box
        public BoundingBox GetBoundingBox()
        {
            return bounding_box;
        }

        public void SetBoundingBox(BoundingBox box)
        {
            bounding_box = box;
        }

        public Vertex[] GetVertices()
        {
            return vertices;
        }

        public void SetVertices(Vertex[] data)
        {                        
            Vector3[] vectors = new Vector3[data.Count()];
            for (int i = 0; i < data.Count(); ++i)
                vectors[i] = data[i].Position;

            SetVerticesAndBoundingBox(data, BoundingBox.CreateFromPoints(vectors));
        }

        public void SetVerticesAndBoundingBox(Vertex[] data, BoundingBox new_bounding_box)
        {
            vertices = data;
            bounding_box = new_bounding_box;
        }

        public Int32[] GetIndices()
        {

            return indices;
        }

        public void SetIndices(Int32[] data)
        {
            indices = data;
        }

        public UInt32 GetVertexCount()
        {
            if (vertices != null)
                return (UInt32)vertices.Count();
            return 0;
        }

        public UInt32 GetIndexCount()
        {
            if (indices != null)
                return (UInt32)indices.Count();
            return 0;
        }

        // vertices
        private Vertex[] vertices = null;
        // indices
        private Int32[] indices = null;

        // bounding box
        BoundingBox bounding_box = new BoundingBox();
    }
}
